package com.wjy.simple.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.wjy.sfhcore.ui.fragment.list.BaseListAdapter;
import com.wjy.sfhcore.ui.third_party.stickylistheaders.StickyListHeadersAdapter;
import com.wjy.sfhcore.util.DensityUtil;
import com.wjy.sfhcore.util.ToastUtil;

/**
 * Created by wangjingyuan on 15/8/1.
 */
public class StickyListAdapter extends BaseListAdapter<String> implements StickyListHeadersAdapter {
    public StickyListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, android.R.layout.simple_expandable_list_item_1, null);
        }
        ((TextView) convertView).setText(getDatas().get(position) + position);
        return convertView;
    }

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            ToastUtil.toast("getHeaderView");
            convertView = new TabLayout(context);
            TabLayout tabLayout = (TabLayout) convertView;
            tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
            tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
            tabLayout.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 35)));
            tabLayout.addTab(tabLayout.newTab().setText("限时特惠"));
            tabLayout.addTab(tabLayout.newTab().setText("注册就送"));
            tabLayout.addTab(tabLayout.newTab().setText("满减"));
            tabLayout.addTab(tabLayout.newTab().setText("限时特惠"));
            tabLayout.addTab(tabLayout.newTab().setText("注册就送"));
            tabLayout.addTab(tabLayout.newTab().setText("满减"));
            tabLayout.addTab(tabLayout.newTab().setText("限时特惠"));
            tabLayout.addTab(tabLayout.newTab().setText("注册就送"));
            tabLayout.addTab(tabLayout.newTab().setText("满减"));
        }
        return convertView;
    }

    @Override
    public long getHeaderId(int position) {
        return 0;
    }

}
